using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using Entities;
/// <summary>
/// Summary description for QuocGiaDAL
/// </summary>
namespace DataAccess
{

    public class QuocGiaDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public QuocGiaDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(QuocGia objQuocGia)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_sp_sp_QuocGia_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@MaQuocGia", SqlDbType.NChar);
            Sqlparam.Value = objQuocGia.MaQuocGia;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@TenQuocGia", SqlDbType.NVarChar);
            Sqlparam.Value = objQuocGia.TenQuocGia;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(QuocGia objQuocGia)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_sp_sp_QuocGia_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Khoa", SqlDbType.BigInt);
            Sqlparam.Value = objQuocGia.Khoa;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MaQuocGia", SqlDbType.NChar);
            Sqlparam.Value = objQuocGia.MaQuocGia;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@TenQuocGia", SqlDbType.NVarChar);
            Sqlparam.Value = objQuocGia.TenQuocGia;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(QuocGia objQuocGia)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_QuocGia_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Khoa", SqlDbType.BigInt);
            Sqlparam.Value = objQuocGia.Khoa;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_QuocGia_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public QuocGia Select(QuocGia objQuocGia)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_QuocGia_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Khoa", SqlDbType.BigInt);
            Sqlparam.Value = objQuocGia.Khoa;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["Khoa"]))
                    objQuocGia.Khoa = Convert.ToInt64(dr["Khoa"]);
                if (!Convert.IsDBNull(dr["MaQuocGia"]))
                    objQuocGia.MaQuocGia = Convert.ToString(dr["MaQuocGia"]);
                if (!Convert.IsDBNull(dr["TenQuocGia"]))
                    objQuocGia.TenQuocGia = Convert.ToString(dr["TenQuocGia"]);

            }
            return objQuocGia;
        }

        public ArrayList SelectAllToArray()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_QuocGia_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrQuocGia = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    QuocGia objQuocGia = new QuocGia();
                    if (!Convert.IsDBNull(dr["Khoa"]))
                        objQuocGia.Khoa = Convert.ToInt64(dr["Khoa"]);
                    if (!Convert.IsDBNull(dr["MaQuocGia"]))
                        objQuocGia.MaQuocGia = Convert.ToString(dr["MaQuocGia"]);
                    if (!Convert.IsDBNull(dr["TenQuocGia"]))
                        objQuocGia.TenQuocGia = Convert.ToString(dr["TenQuocGia"]);
                    arrQuocGia.Add(objQuocGia);
                }
            }
            return arrQuocGia;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_QuocGia_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }


        #endregion

    }

}
